package com.wetech.demo.web3j.contracts.erc7579utils;

import io.reactivex.Flowable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.web3j.abi.EventEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.CustomError;
import org.web3j.abi.datatypes.DynamicBytes;
import org.web3j.abi.datatypes.Event;
import org.web3j.abi.datatypes.generated.Bytes1;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.request.EthFilter;
import org.web3j.protocol.core.methods.response.BaseEventResponse;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;
import org.web3j.tx.gas.ContractGasProvider;

/**
 * <p>Auto generated code.
 * <p><strong>Do not modify!</strong>
 * <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
 * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the 
 * <a href="https://github.com/LFDT-web3j/web3j/tree/main/codegen">codegen module</a> to update.
 *
 * <p>Generated with web3j version 4.14.0.
 */
@SuppressWarnings("rawtypes")
public class ERC7579Utils extends Contract {
    public static final String BINARY = "60556032600b8282823980515f1a607314602657634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe730000000000000000000000000000000000000000301460806040525f5ffdfea2646970667358221220fbc54fa260977ba1e3a996a650037c50ca804329770367fd3b4d5afc0b3cbde164736f6c634300081d0033";

    private static String librariesLinkedBinary;

    public static final CustomError ERC7579ALREADYINSTALLEDMODULE_ERROR = new CustomError("ERC7579AlreadyInstalledModule", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<Address>() {}));
    ;

    public static final CustomError ERC7579DECODINGERROR_ERROR = new CustomError("ERC7579DecodingError", 
            Arrays.<TypeReference<?>>asList());
    ;

    public static final CustomError ERC7579MISMATCHEDMODULETYPEID_ERROR = new CustomError("ERC7579MismatchedModuleTypeId", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<Address>() {}));
    ;

    public static final CustomError ERC7579UNINSTALLEDMODULE_ERROR = new CustomError("ERC7579UninstalledModule", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<Address>() {}));
    ;

    public static final CustomError ERC7579UNSUPPORTEDCALLTYPE_ERROR = new CustomError("ERC7579UnsupportedCallType", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes1>() {}));
    ;

    public static final CustomError ERC7579UNSUPPORTEDEXECTYPE_ERROR = new CustomError("ERC7579UnsupportedExecType", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes1>() {}));
    ;

    public static final CustomError ERC7579UNSUPPORTEDMODULETYPE_ERROR = new CustomError("ERC7579UnsupportedModuleType", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    ;

    public static final Event ERC7579TRYEXECUTEFAIL_EVENT = new Event("ERC7579TryExecuteFail", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<DynamicBytes>() {}));
    ;

    @Deprecated
    protected ERC7579Utils(String contractAddress, Web3j web3j, Credentials credentials,
            BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    protected ERC7579Utils(String contractAddress, Web3j web3j, Credentials credentials,
            ContractGasProvider contractGasProvider) {
        super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
    }

    @Deprecated
    protected ERC7579Utils(String contractAddress, Web3j web3j,
            TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    protected ERC7579Utils(String contractAddress, Web3j web3j,
            TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
        super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
    }

    public static List<ERC7579TryExecuteFailEventResponse> getERC7579TryExecuteFailEvents(
            TransactionReceipt transactionReceipt) {
        List<Contract.EventValuesWithLog> valueList = staticExtractEventParametersWithLog(ERC7579TRYEXECUTEFAIL_EVENT, transactionReceipt);
        ArrayList<ERC7579TryExecuteFailEventResponse> responses = new ArrayList<ERC7579TryExecuteFailEventResponse>(valueList.size());
        for (Contract.EventValuesWithLog eventValues : valueList) {
            ERC7579TryExecuteFailEventResponse typedResponse = new ERC7579TryExecuteFailEventResponse();
            typedResponse.log = eventValues.getLog();
            typedResponse.batchExecutionIndex = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            typedResponse.returndata = (byte[]) eventValues.getNonIndexedValues().get(1).getValue();
            responses.add(typedResponse);
        }
        return responses;
    }

    public static ERC7579TryExecuteFailEventResponse getERC7579TryExecuteFailEventFromLog(Log log) {
        Contract.EventValuesWithLog eventValues = staticExtractEventParametersWithLog(ERC7579TRYEXECUTEFAIL_EVENT, log);
        ERC7579TryExecuteFailEventResponse typedResponse = new ERC7579TryExecuteFailEventResponse();
        typedResponse.log = log;
        typedResponse.batchExecutionIndex = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
        typedResponse.returndata = (byte[]) eventValues.getNonIndexedValues().get(1).getValue();
        return typedResponse;
    }

    public Flowable<ERC7579TryExecuteFailEventResponse> eRC7579TryExecuteFailEventFlowable(
            EthFilter filter) {
        return web3j.ethLogFlowable(filter).map(log -> getERC7579TryExecuteFailEventFromLog(log));
    }

    public Flowable<ERC7579TryExecuteFailEventResponse> eRC7579TryExecuteFailEventFlowable(
            DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(ERC7579TRYEXECUTEFAIL_EVENT));
        return eRC7579TryExecuteFailEventFlowable(filter);
    }

    @Deprecated
    public static ERC7579Utils load(String contractAddress, Web3j web3j, Credentials credentials,
            BigInteger gasPrice, BigInteger gasLimit) {
        return new ERC7579Utils(contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    @Deprecated
    public static ERC7579Utils load(String contractAddress, Web3j web3j,
            TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return new ERC7579Utils(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    public static ERC7579Utils load(String contractAddress, Web3j web3j, Credentials credentials,
            ContractGasProvider contractGasProvider) {
        return new ERC7579Utils(contractAddress, web3j, credentials, contractGasProvider);
    }

    public static ERC7579Utils load(String contractAddress, Web3j web3j,
            TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
        return new ERC7579Utils(contractAddress, web3j, transactionManager, contractGasProvider);
    }

    public static RemoteCall<ERC7579Utils> deploy(Web3j web3j, Credentials credentials,
            ContractGasProvider contractGasProvider) {
        return deployRemoteCall(ERC7579Utils.class, web3j, credentials, contractGasProvider, getDeploymentBinary(), "");
    }

    @Deprecated
    public static RemoteCall<ERC7579Utils> deploy(Web3j web3j, Credentials credentials,
            BigInteger gasPrice, BigInteger gasLimit) {
        return deployRemoteCall(ERC7579Utils.class, web3j, credentials, gasPrice, gasLimit, getDeploymentBinary(), "");
    }

    public static RemoteCall<ERC7579Utils> deploy(Web3j web3j,
            TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
        return deployRemoteCall(ERC7579Utils.class, web3j, transactionManager, contractGasProvider, getDeploymentBinary(), "");
    }

    @Deprecated
    public static RemoteCall<ERC7579Utils> deploy(Web3j web3j,
            TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return deployRemoteCall(ERC7579Utils.class, web3j, transactionManager, gasPrice, gasLimit, getDeploymentBinary(), "");
    }

    public static void linkLibraries(List<Contract.LinkReference> references) {
        librariesLinkedBinary = linkBinaryWithReferences(BINARY, references);
    }

    private static String getDeploymentBinary() {
        if (librariesLinkedBinary != null) {
            return librariesLinkedBinary;
        } else {
            return BINARY;
        }
    }

    public static class ERC7579TryExecuteFailEventResponse extends BaseEventResponse {
        public BigInteger batchExecutionIndex;

        public byte[] returndata;
    }
}
